

from rest_framework.response import Response


def data_response(status_code, message, data=None):
    response_data = {
        'code': 0 if status_code == 200 else 1 ,
        'status': status_code,
        'message': message,
        'data': data

    }
    return Response(response_data, status=status_code)

def error_response(status_code, errors):

    msg = ''
    for field, err in errors.items():
        msg += f' {err[0]}'
    msg = msg.rstrip('; ')
    response_data = {
        'code':  1 ,
        'status': 400,
        'message': msg
    }
    return Response(response_data, status=status_code)